import Vue from 'vue'
import Router from 'vue-router'
import store from '@/store'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    meta: { title: '404' },
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: '数据总览',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '数据总览', icon: 'dashboard' }
    }]
  },

  // 学生管理
  {
    path: '/student',
    component: Layout,
    redirect: '/student/list',
    //name: 'Vod',
    name: '学生管理',
    meta: { title: '学生管理', icon: 'el-icon-s-order' },
    children: [
      {
        path: 'list',
        name: 'StudentList',
        component: () => import('@/views/student/list'),
        meta: { title: '学生列表', icon: 'el-icon-user' }
      },
      {
        path: 'add',
        name: 'AddStudent',
        component: () => import('@/views/student/add'),
        meta: { title: '添加学生', icon: 'el-icon-circle-plus-outline' }
      },
      {
        path: 'edit/:id',
        name: 'EditStudent',
        hidden: true,
        component: () => import('@/views/student/add'),
        meta: { title: '编辑', icon: 'el-icon-edit' }
      },
      {
        path: 'graduated',
        name: 'Graduated',
        component: () => import('@/views/student/list'),
        meta: { title: '毕业学生', icon: 'el-icon-switch-button\n' }
      },
      {
        path: 'strecovery',
        name: 'stRecovery',
        component: () => import('@/views/student/list'),
        meta: { title: '误删恢复', icon: 'el-icon-refresh' }
      }
    ]
  },

  // 成绩管理
  {
    path: '/course',
    component: Layout,
    redirect: '/course/list',
    //name: 'Course',
    name: '成绩管理',
    meta: { title: '成绩管理', icon: 'el-icon-star-on' },
    children: [
      {
        path: 'list',
        name: 'CourseList',
        component: () => import('@/views/course/list'),
        meta: { title: '班级成绩', icon: 'el-icon-document' }
      }, {
        path: 'add',
        name: 'AddCourse',
        component: () => import('@/views/course/add'),
        meta: { title: '成绩录入', icon: 'el-icon-thumb' }
      },
    ]
  },


  //考试管理
  {
    path: '/test',
    component: Layout,
    name: '考试管理',
    meta: { title: '考试管理', icon: 'el-icon-s-management' },
    redirect: '/test/list',
    children: [{
      path: 'list',
      name: 'TestList',
      component: () => import('@/views/test/list'),
      meta: { title: '考试列表', icon: 'el-icon-s-data' }
    }, {
      path: 'subject',
      name: 'TestSubject',
      component: () => import('@/views/test/subject'),
      meta: { title: '考试科目', icon: 'el-icon-s-claim' }
    }]
  },
  // 班级管理
  {
    path: '/class',
    component: Layout,
    name: '班级管理',
    redirect: '/class/list',
    // meta: { title: '班级管理', icon: 'el-icon-s-help' },
    children: [{
      path: 'list',
      name: 'ClassList',
      component: () => import('@/views/class/list'),
      meta: { title: '班级管理', icon: 'el-icon-s-marketing' }
    }]
  },

  // 教师管理
  {
    path: '/teacher',
    component: Layout,
    name: '教师管理',
    redirect: '/teacher/list',
    meta: { title: '教师管理', icon: 'el-icon-s-help' },
    children: [{
      path: 'list',
      name: 'TeacherList',
      component: () => import('@/views/teacher/index'),
      meta: { title: '教师列表', icon: 'el-icon-s-custom' }
    }, {
      path: 'terecovery',
      name: 'teRecovery',
      component: () => import('@/views/teacher/index'),
      meta: { title: '误删恢复', icon: 'el-icon-refresh' }
    }]
  },

  // 学院管理
  {
    path: '/college',
    component: Layout,
    name: '学院管理',
    redirect: '/college/list',
    // meta: { title: '学院管理', icon: 'el-icon-s-help' },
    children: [{
      path: 'list',
      name: 'CollegeList',
      component: () => import('@/views/college/index'),
      meta: { title: '学院管理', icon: 'el-icon-s-platform' }
    }]
  },

  // 专业管理
  {
    path: '/major',
    component: Layout,
    name: '专业管理',
    redirect: '/major/list',
    // meta: { title: '专业管理', icon: 'el-icon-s-help' },
    children: [{
      path: 'list',
      name: 'MajorList',
      component: () => import('@/views/major/index'),
      meta: { title: '专业管理', icon: 'el-icon-s-unfold' }
    }]
  },

  // 学生档案
  {
    path: '/portfolio',
    component: Layout,
    redirect: '/portfolio/list',
    meta: { title: '学生档案', icon: 'el-icon-s-flag' },
    name: '学生档案',
    children: [{
      path: 'list',
      name: 'PortfolioList',
      component: () => import('@/views/portfolio/index'),
      meta: { title: '学生档案', icon: 'el-icon-finished' }
    }]
  },

  // 系统设置
  {
    path: '/password',
    component: Layout,
    redirect: '/password/edit',
    name: '修改密码',
    children: [{
      path: 'edit',
      name: 'PasswordEdit',
      component: () => import('@/views/password/index'),
      meta: { title: '修改密码', icon: 'el-icon-lock' }
    }
    ]
  },

  // 权限管理
  {
    path: '/roles',
    component: Layout,
    redirect: '/roles/account',
    name: '权限管理',
    meta: { title: '权限管理', icon: 'el-icon-s-check' },
    children: [{
      path: 'account',
      name: 'SystemAccount',
      component: () => import('@/views/roles/account'),
      meta: { title: '账户管理', icon: 'el-icon-lock' }
    }, {
      path: 'adminrole',
      name: 'SystemAdminrole',
      component: () => import('@/views/roles/adminrole'),
      meta: { title: '权限分配', icon: 'el-icon-turn-off' }
    }
    ]
  },

  //个人中心
  {
    path: '/personal',
    component: Layout,
    redirect: '/personal/list',
    name: '个人信息',
    children: [{
      path: 'list',
      name: 'PersonalList',
      component: () => import('@/views/personal'),
      meta: { title: '个人信息', icon: 'el-icon-finished' }
    }]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()



export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
